package com.mfin.bom.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.mfin.bom.interfaces.ICustomer;
import com.mfin.bom.interfaces.IFinance;
import com.mfin.bom.interfaces.IPartner;
import com.mfin.bom.objects.Customer;
import com.mfin.bom.objects.Finance;
import com.mfin.bom.objects.Partner;
import com.mfin.vo.ObjectKey;

public class FinanceAdapter extends IIdentifiableAdapter implements IFinance {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5453196486895749628L;

	Finance wrapFinance = null;

	public FinanceAdapter(Finance fb) {
		wrapFinance = fb;
		ObjectKey[] newKeys = new ObjectKey[1];
		newKeys[0] = new ObjectKey(wrapFinance.getId());
		setKeys(newKeys);
	}

	public Finance getFinance() {
		return wrapFinance;
	}

	@Override
	public void setFinanceName(String financeName) {
		wrapFinance.setFinanceName(financeName);
	}

	@Override
	public void setFinanceNumber(Long financeNumber) {
		wrapFinance.setId(financeNumber);
	}

	@Override
	public Long getFinanceNumber() {
		return wrapFinance.getId();
	}

	@Override
	public String getFinanceName() {
		return wrapFinance.getFinanceName();
	}

	@Override
	public List<ICustomer> getCustomers() {
		Set<Customer> customers = wrapFinance.getCustomers();
		List<ICustomer> customerList = null;

		if (customers != null) {
			customerList = new ArrayList<ICustomer>();
			for (Customer customer : customers) {
				customerList.add(new CustomerAdapter(customer, getKeys()));
			}
		}
		return customerList;
	}

	@Override
	public List<IPartner> getPartners() {
		Set<Partner> partners = wrapFinance.getPartners();
		List<IPartner> partnerList = null;

		if (partners != null) {
			partnerList = new ArrayList<IPartner>();
			for (Partner partner : partners) {
				partnerList.add(new PartnerAdapter(partner, getKeys()));
			}
		}
		return partnerList;
	}
}
